import type { NextFunction, Request, Response } from "express";
import { commLog } from "../utils/log";

/** 追踪客户端访问信息 */
export const traceLog = async (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  commLog.trace(`客户端访问信息 IP:${req.ip} ${req.method}:${req.url}`);
  if (req.method === "GET" && Object.keys(req.query).length > 0)
    commLog.trace("请求参数:", req.query);
  if (req.method === "POST") commLog.trace("请求JSON:", req.body);
  next();
};
